import React, { Component } from 'react'
import { createOrder } from '../../api/order';

export default class OrderSubmit extends Component {
    submit = () => {
        const { preOrderId, sum } = this.props.location.state;
        createOrder({
            "addressInfo": "联系信息(必须)",
            "allFee": sum,
            "discount": 0,
            "preOrderId": preOrderId
        }).then(res => {
            if (res.data.code === 666) {
                this.props.history.push({
                    pathname: 'orderpay', state: { data: res.data.result }
                })
            }
        })
    }
    render() {
        const { cartList } = this.props.location.state;
        return (
            <div>
                <h3>商品列表</h3>
                <ul>{
                    cartList.map(item => <li key={item.id}>{item.name}</li>)
                }</ul>
                <h3>微信扫码支付</h3>
                <button onClick={this.submit}>提交订单</button>
            </div>
        )
    }
}
